package cn.wolfcode.trip.base.service.impl;


import cn.wolfcode.trip.base.domain.DailyComment;
import cn.wolfcode.trip.base.mapper.DailyCommentMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IDailyCommentService;
import cn.wolfcode.trip.base.util.UserContext;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class DailyCommentServiceImpl implements IDailyCommentService {
    @Autowired
    private DailyCommentMapper dailyCommentMapper;


    @Override
    public void saveOrUpdate(DailyComment dailyComment) {
        Date date = new Date();

        if(dailyComment.getId() == null){
            dailyComment.setCreateTime(date);
            //dailyComment.setUser(UserContext.getUserAttribute());
            dailyCommentMapper.insert(dailyComment);

        }else {
            dailyCommentMapper.updateByPrimaryKey(dailyComment);
        }
    }



    @Override
    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize(), qo.getOrderBy());
        List<DailyComment> list = dailyCommentMapper.queryForList(qo);
        return new PageInfo(list);
    }

    @Override
    public List queryComments(Long userId) {
        List dailycomments=dailyCommentMapper.queryComments(userId);
        return dailycomments;
    }


}
